package com.zhong.auth.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.zhong.auth.common.enums.AuthUserStatusEnum;
import com.zhong.auth.common.enums.IsDeleteFlagEnum;
import com.zhong.auth.domain.bo.AuthRoleBO;
import com.zhong.auth.domain.convert.AuthRoleBOConvert;
import com.zhong.auth.domain.service.AuthRoleDomainService;
import com.zhong.auth.infra.basic.entity.AuthRole;
import com.zhong.auth.infra.basic.service.AuthRoleService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    AuthRoleService authRoleService;

    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.add.authRoleBO: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConvert.INSTANCE.convertBOToEntity(authRoleBO);
        authRole.setIsDelete(IsDeleteFlagEnum.UN_DELETE.getCode());
        authRole.setStatus(AuthUserStatusEnum.OPEN.getCode());
        Integer count = authRoleService.insert(authRole);
        return  count > 0;
    }

    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.delete.authRoleBO: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConvert.INSTANCE.convertBOToEntity(authRoleBO);
        authRole.setIsDelete(IsDeleteFlagEnum.DELETE.getCode());
        Integer count = authRoleService.update(authRole);
        return  count > 0;
    }

    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.delete.authRoleBO: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConvert.INSTANCE.convertBOToEntity(authRoleBO);
        Integer count = authRoleService.update(authRole);
        return  count > 0;
    }
}
